package main

import "fmt"

/*
map的创建，遍历，取键值
*/
func createMap() {
	fmt.Println("map的创建")
	m1 := map[string]string{
		"name":    "candywall",
		"phone":   "18812345678",
		"address": "北京三里屯",
	}

	fmt.Println(m1)

	m2 := make(map[int]int)
	fmt.Println(m2)

	var m3 map[string]int
	fmt.Println(m3)

	fmt.Println("map的遍历")
	for k, v := range m1 {
		fmt.Println(k, v)
	}

	fmt.Println("根据键获取值")
	phone, ok := m1["phone"]
	fmt.Println(phone, ok)
	if phone, ok := m1["telephone"]; ok {
		fmt.Println(phone)
	} else {
		fmt.Println("键不存在！")
	}

	fmt.Println("根据键删除元素")
	delete(m1, "address")
	fmt.Println(m1)
}

func main() {
	createMap()
}
